<template>
  <div class="tabcontrol">
    <div
      v-for="(item, index) in title"
      :key="index"
      class="item"
      :class="{ active: currentIndex === index }"
      @click="itemClick(index)"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>
<script>
export default {
  name: "TabControl",
  props: {
    title: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index;
      this.$emit("tabClick", index);
    },
  },
};
</script>
<style scoped>
.tabcontrol {
  background-color: #fff;
  text-align: center;
  display: flex;
}
.tabcontrol .item {
  flex: 1;
  height: 40px;
  line-height: 40px;
}
.active {
  color: red;
}
.active span {
  padding: 6px;
  border-bottom: 2px solid red;
}
</style>